<script lang="ts" setup>
import { useRouter } from 'vue-router'
import { NavBar as VanNavBar } from 'vant'
// 创建路由对象
const router = useRouter()
const props = defineProps<{ title?: string; rightText?: string; back?: () => void }>()
const onClickLeft = () => {
  if (props.back) {
    props.back()

    return
  }

  if (history.state.back) {
    router.back()
  } else {
    router.push('/')
  }
}
const emit = defineEmits<{
  (e: 'right-click'): void
}>()
const onClickRight = () => {
  emit('right-click')
}
</script>

<template>
  <div class="">
    <van-nav-bar
      fixed
      placeholder
      :title="title"
      :right-text="rightText"
      left-arrow
      @click-left="onClickLeft"
      @click-right="onClickRight"
    />
  </div>
</template>

<style scoped lang="scss">
:deep() {
  .van-nav-bar {
    &__arrow {
      font-size: 18px;
      color: var(--cp-text1);
    }
    &__text {
      font-size: 15px;
    }
  }
}
</style>
